package org.haredot.controller;

import org.haredot.annotation.LogModule;
import org.haredot.entity.Position;
import org.haredot.service.PositionService;
import org.haredot.vo.ResultVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@LogModule("岗位管理")
@RestController
@RequestMapping("/position")
public class PositionController {

    @Resource
    private PositionService positionService ;

    @GetMapping("/list")
    @PreAuthorize("hasAuthority('job:view')")
    public ResultVo<?> list() {
        return positionService.queryPositions();
    }

    @PostMapping("/add")
    @PreAuthorize("hasAuthority('job:view:add')")
    public ResultVo<?> addPosition(@RequestBody Position position) {
        return positionService.savePosition(position);
    }

    @PutMapping("/modify{id}")
    @PreAuthorize("hasAuthority('job:view:modify')")
    public ResultVo<?> addPosition(@PathVariable("id") Long id, @RequestBody Position position) {
        return positionService.modifyPosition(id, position);
    }

    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasAuthority('job:view:remove')")
    public ResultVo<?> removePosition(@PathVariable("id") Long id) {
        return positionService.removePosition(id);
    }
}
